import Vue from 'vue'
import App from './App'
// import api from '@/common/http/'
import http from '@/common/http/'

// http.config.baseUrl = 'http://grid.tripln.top/api/'
// http.config.baseUrl = 'http://192.168.31.150:8081/api/'
http.config.baseUrl = 'http://192.168.31.155:8081/api/'
let token = "";
http.interceptor.request = (config) => {
	
	uni.getStorage({
		key: "accessToken",
		success: function(res) {
			// console.log("存储的token333333  " + res.data);
			if(res.data){
				token = "bearer." + res.data;
			}
		},
		fail: function(error) {
		}
	})
	config.header = {
		"scpid": token
	}
}

http.interceptor.response = (response) => {
	if (response.statusCode === 200) {
		if (response.data.errcode === 1001) {
			uni.reLaunch({
				url: "/pages/login/login"
			});
			return uni.showToast({
				icon:'none',
				title: '请登录',
				duration: 1500
			})
		}
		return response.data;
	} else {
		uni.showToast({
			icon:'none',
			title: "网络异常"
		});
	}

	return response;
}
Vue.config.productionTip = false
// Vue.prototype.$api = api
Vue.prototype.$http = http
Vue.prototype.$eventHub = new Vue();

App.mpType = 'app'

const app = new Vue({
	...App
})
app.$mount()
